home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / GNU Diff Sources / GNU DIFF 1.15b Sources / stat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-20  |  2.6 KB  |  129 lines  |  [TEXT/ALFA]

  1.  
  2. #include    <MacHeaders>
  3. #include    <Files.h>
  4. #include    "diff.h"
  5.  
  6. static    long    lastInode;
  7.  
  8. int
  9. fstat (int fd, struct stat *theStat)
  10.     {
  11.     memset (theStat, 0, sizeof(*theStat));
  12.     theStat->st_mode = 0 /*S_IFSTREAM*/;
  13.     theStat->st_ito = ++lastInode;
  14.     return (0);
  15.     }
  16.  
  17.  
  18. int
  19. stat (xname, theStat)
  20.     char    *xname;
  21.     register    struct    stat    *theStat;
  22.     {
  23.     unsigned    char    name[256];
  24.     int    retval;
  25.     CInfoPBRec    info;
  26.     
  27.     strncpy ((char *)name, xname, 255);
  28.     CtoPstr ((void *)name);
  29.     
  30.     memset (&info, 0, sizeof(info));
  31.     retval = PBHGetVolSync ((WDPBPtr)&info);
  32.     if ( ! errno )
  33.         errno = retval;
  34.     if ( retval )
  35.         return (retval);
  36.     info.hFileInfo.ioNamePtr = name;
  37.     retval = PBGetCatInfoSync (&info);
  38.     if ( ! errno )
  39.         errno = retval;
  40.  
  41.     theStat->st_mtime = info.hFileInfo.ioFlMdDat;
  42.     theStat->st_size = info.hFileInfo.ioFlLgLen;
  43.     if ( info.hFileInfo.ioFlAttrib & ioDirMask )
  44.     {
  45.         theStat->st_mode = S_IFDIR;
  46.     }
  47.     else
  48.     {
  49.         theStat->st_mode = S_IFREG;
  50.     }
  51.     theStat->st_ito = ++lastInode;
  52.     return (retval);
  53.     }
  54.  
  55. #ifdef    NOTDEF
  56. /*
  57. ** due to difference of opinion btw gnu and microsoft about what
  58. ** const means, const is defined away in diff.h, which causes warnings
  59. ** when compiling the headers.  This ugliness is avoided here.
  60. */
  61. #ifdef const
  62. #undef const
  63. #endif
  64. #include <string.h>
  65.  
  66. DIR *
  67. opendir(char *name) {
  68.     unsigned char localname[65];
  69.     CInfoPBRec    info;
  70.     int    errorReturned;
  71.     DIR *rval;
  72.     
  73.     strcpy((char *)localname,name);
  74.     CtoPstr ((void *)localname);
  75.     memset (&info, 0, sizeof(info));
  76.     errorReturned = PBHGetVolSync ((WDPBPtr)&info);
  77.     if ( ! errno )
  78.         errno = errorReturned;
  79.     if ( errorReturned )
  80.         return (NULL);
  81.     info.dirInfo.ioNamePtr = localname;
  82.     errorReturned = PBGetCatInfoSync (&info);
  83.     if ( ! errno )
  84.         errno = errorReturned;
  85.     if ( errorReturned )
  86.         return (NULL);
  87.     rval = (void *)NewPtrClear((long)sizeof(DIR));
  88.     rval->vRefNum = info.dirInfo.ioVRefNum;
  89.     rval->dirID = info.dirInfo.ioDrDirID;
  90.     rval->totalCount = info.dirInfo.ioDrNmFls;
  91.     
  92.     return rval;
  93. }
  94.  
  95. void
  96. closedir(DIR *x) {
  97.     free(x);
  98. }
  99.  
  100. struct direct *
  101. readdir(DIR *thisdir) {
  102.     int    errorReturned;
  103.     
  104.     /*
  105.     ** first time through, we don't need to look for a file
  106.     */
  107.     CInfoPBRec    info;
  108.     
  109.     if ( thisdir->currCount >= thisdir->totalCount )    
  110.         return (NULL);
  111.     memset (&info, 0, sizeof(info));
  112.     thisdir->current.d_name[0] = 0;
  113.     info.hFileInfo.ioNamePtr = (unsigned char *)&thisdir->current.d_name;
  114.     info.hFileInfo.ioVRefNum = thisdir->vRefNum;
  115.     info.hFileInfo.ioDirID = thisdir->dirID;
  116.     info.hFileInfo.ioFDirIndex = thisdir->currCount + 1;
  117.     errorReturned = PBGetCatInfoSync (&info);
  118.     
  119.     if ( ! errno )
  120.         errno = errorReturned;
  121.     if ( errorReturned )
  122.         return (NULL);
  123.         
  124.     PtoCstr ((void *)&thisdir->current.d_name);
  125.     thisdir->currCount++;
  126.     return &thisdir->current;
  127. }
  128. #endif    NOTDEF
  129.